package beans;

/**
 * Created with IntelliJ IDEA.
 * User: Joshua
 * Date: 7/17/12
 * Time: 6:24 PM
 * A bean to hold the user's information to check against a database.
 */
public class UserBean {
    private String userid;
    private String password;

    ////////////////////////////////////////////////
    //gettters and setters
    public String getUserid(){
        return userid;
    }

    public void setUserid(String userid){
        if(validateUserid(userid))
            this.userid = userid;
        else this.userid = "";
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        if(validatePassword(password))
            this.password = password;
        else this.password = "";
    }

    ///////////////////////////////////////////////
    //validators
    public boolean validateUserid(String userid){
        //usernames may only be alphanumeric with exceptions being
        //-_
        return userid.matches("^[a-z0-9_.-]{3,15}$");
    }

    public boolean validatePassword(String userid){
        //usernames can contain alphanumeric letters or certain
        //special cahracters and must be between 6 and 20 chars long
        return userid.matches("^[A-z0-9_.!@#$%^&+-]{6,20}$");
    }
}
